added Feb 2001 SDK
[windows-sources.git] / shared source / wpf / src / host / shimimpl / persisthistory.cxx
blob11f28b6d26d1ed1a2f25445adf0b30797f250f7d
1 //+-----------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // Description:
6 // Defines the PersistHistory class of PresentationHost.
7 //
8 // History:
9 // 2002/06/19-murrayw
10 // Created
11 // 2007/09/20-[....]
12 // Ported Windows->DevDiv. See SourcesHistory.txt.
14 //------------------------------------------------------------------------
16 #include "Precompiled.hxx"
17 #include "PersistHistory.hxx"
18 #include "HostShim.hxx"
19 #include "Version.hxx"
21 // This macro will keep the types in [....] between the LoadHistoryHelper and SaveHistoryHelper methods.
22 #define STARTUP_URI_LENGTH_TYPE ULONG
24 /******************************************************************************
25 CPersistHistory::CPersistHistory()
26 ******************************************************************************/
27 CPersistHistory::CPersistHistory(CHostShim *pHostShim)
29 m_pHostShim = pHostShim;
32 /******************************************************************************
33 CPersistHistory::~CPersistHistory()
34 ******************************************************************************/
35 CPersistHistory::~CPersistHistory()
39 /******************************************************************************
40 CPersistHistory::QueryInterface()
41 ******************************************************************************/
42 STDMETHODIMP CPersistHistory::QueryInterface(REFIID riid, LPVOID *ppReturn)
44 return m_pHostShim->QueryInterface(riid, ppReturn);
47 /******************************************************************************
48 CPersistHistory::AddRef()
49 ******************************************************************************/
50 STDMETHODIMP_(ULONG) CPersistHistory::AddRef()
52 return m_pHostShim->AddRef();
55 /******************************************************************************
56 CPersistHistory::Release()
57 ******************************************************************************/
58 STDMETHODIMP_(ULONG) CPersistHistory::Release()
60 return m_pHostShim->Release();
63 /******************************************************************************
64 CPersistHistory::GetClassID()
65 ******************************************************************************/
66 STDMETHODIMP CPersistHistory::GetClassID(LPCLSID pClassID)
68 return m_pHostShim->GetClassID(pClassID);
71 /******************************************************************************
72 CPersistHistory::SetPositionCookie
73 ******************************************************************************/
74 STDMETHODIMP CPersistHistory::SetPositionCookie(DWORD /*dwPositionCookie*/)
76 return S_OK;
79 /******************************************************************************
80 CPersistHistory::GetPositionCookie
81 ******************************************************************************/
82 STDMETHODIMP CPersistHistory::GetPositionCookie(__out DWORD* pdwPositionCookie)
84 HRESULT hr = S_OK;
86 CK_PARG(pdwPositionCookie);
88 *pdwPositionCookie = 0;
90 Cleanup:
92 return hr;
95 /**************************************************************************
96 CPersistHistory::SaveHistory(IStream *pStream)
97 **************************************************************************/
98 STDMETHODIMP CPersistHistory::SaveHistory(__in IStream* pSaveStream)
100 HRESULT hr = S_OK;
102 CKHR(m_pHostShim->RequestedVersion()->WriteToStream(pSaveStream));
103 CKHR(WriteToStream(pSaveStream, (DWORD) m_pHostShim->GetMimeType()));
104 CKHR(m_pHostShim->StartupUri()->WriteToStream(pSaveStream));
105 CKHR(m_pHostShim->StartupLocation()->WriteToStream(pSaveStream));
106 CKHR(m_pHostShim->ApplicationIdentity()->WriteToStream(pSaveStream));
108 if(!m_pHostShim->GetVersion())
110 CKHR(E_UNEXPECTED);
112 CKHR(m_pHostShim->GetVersion()->SaveToHistory(pSaveStream));
114 Cleanup:
115 return hr;
118 /**************************************************************************
119 CPersistHistory::LoadHistory(IStream *pStream, IBindCtx *pbc)
120 **************************************************************************/
121 STDMETHODIMP CPersistHistory::LoadHistory(__in IStream* pLoadStream, IBindCtx* pBindCtx)
123 HRESULT hr = S_OK;
125 // When doing navigations inside of an app, history is saved without going through
126 // CPersistHistory::SaveHistory, so the information that puts in the stream isn't there.
127 // This check is to be sure that we are being activated by IPersistHistory.
129 if (!m_pHostShim->GetVersion())
131 CKHR(m_pHostShim->RequestedVersion()->ReadFromStream(pLoadStream));
133 DWORD mimeType;
134 CKHR(ReadFromStream(pLoadStream, &mimeType));
135 m_pHostShim->SetMimeType((MimeType)mimeType);
137 CKHR(m_pHostShim->StartupUri()->ReadFromStream(pLoadStream));
138 CKHR(m_pHostShim->StartupLocation()->ReadFromStream(pLoadStream));
139 CKHR(m_pHostShim->ApplicationIdentity()->ReadFromStream(pLoadStream));
141 pLoadStream->AddRef();
142 m_pHostShim->SetHistoryStream(pLoadStream);
144 m_pHostShim->Execute(); //[Watson on error]
147 CKHR(m_pHostShim->GetVersion()->LoadFromHistory(pLoadStream, pBindCtx));
149 Cleanup:
150 return hr;
153 STDMETHODIMP CPersistHistory::ReadFromStream(IStream* pInputStream, DWORD* pdwData)
155 HRESULT hr = S_OK;
157 CHECK_POINTER(pdwData);
159 ULONG bytesRead = 0;
160 CKHR(pInputStream->Read((void*)pdwData, sizeof(*pdwData), &bytesRead));
162 Cleanup:
163 return hr;
166 STDMETHODIMP CPersistHistory::WriteToStream(IStream* pOutputStream, DWORD dwData)
168 HRESULT hr = S_OK;
170 ULONG bytesWritten = 0;
171 CKHR(pOutputStream->Write((void*)&dwData, sizeof(dwData), &bytesWritten));
173 Cleanup:
174 return hr;